package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryCalculateRuleAddDTO;
import org.jsola.hr.dto.SalaryCalculateRuleUpdateDTO;
import org.jsola.hr.entity.SalaryCalculateRuleDO;
import org.jsola.hr.query.SalaryCalculateRuleQuery;
import org.jsola.hr.service.ISalaryCalculateRuleService;
import org.jsola.hr.vo.SalaryCalculateRuleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 工价计算规则
 *
 * @author zhr
 */
@Component
public class SalaryCalculateRuleTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISalaryCalculateRuleService salaryCalculateRuleService;

    /**
     * 生成add测试数据
     * @return SalaryCalculateRuleAddDTO
     */
    public SalaryCalculateRuleAddDTO getSalaryCalculateRuleAddDTO(){
        SalaryCalculateRuleAddDTO salaryCalculateRuleAddDTO = new SalaryCalculateRuleAddDTO();
        salaryCalculateRuleAddDTO.setSalaryCalculateRuleGroupId(getRandomValue("varchar",32));
        salaryCalculateRuleAddDTO.setName(getRandomValue("text",2147483647));
        salaryCalculateRuleAddDTO.setTimeType(SafeKit.getInteger(getRandomValue("int",4)));
        salaryCalculateRuleAddDTO.setTimeJson(getRandomValue("text",2147483647));
        salaryCalculateRuleAddDTO.setRuleType(SafeKit.getInteger(getRandomValue("int",11)));
        salaryCalculateRuleAddDTO.setShowType(SafeKit.getInteger(getRandomValue("int",4)));
        salaryCalculateRuleAddDTO.setLeaveShowType(SafeKit.getInteger(getRandomValue("int",4)));
        salaryCalculateRuleAddDTO.setHourAmount(SafeKit.getLong(getRandomValue("bigint",20)));
        salaryCalculateRuleAddDTO.setHourAmountRule(getRandomValue("text",2147483647));
        salaryCalculateRuleAddDTO.setRedPacketRule(getRandomValue("text",2147483647));
        salaryCalculateRuleAddDTO.setLeaveOfficeRule(getRandomValue("text",2147483647));
        salaryCalculateRuleAddDTO.setDissatisfyMonth(SafeKit.getInteger(getRandomValue("int",4)));
        salaryCalculateRuleAddDTO.setEndAstrict(SafeKit.getInteger(getRandomValue("int",4)));
        salaryCalculateRuleAddDTO.setEndAstrictJson(getRandomValue("text",2147483647));
        salaryCalculateRuleAddDTO.setCommissionRatio(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryCalculateRuleAddDTO.setSpecialCost(SafeKit.getLong(getRandomValue("bigint",20)));
        salaryCalculateRuleAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        return salaryCalculateRuleAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryCalculateRuleUpdateDTO
     */
    public SalaryCalculateRuleUpdateDTO getSalaryCalculateRuleUpdateDTO(SalaryCalculateRuleVO salaryCalculateRuleVO){
        return salaryCalculateRuleService.selectDOById(salaryCalculateRuleVO.getId(), SITE_ID).to(SalaryCalculateRuleUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryCalculateRuleQuery
     */
    public SalaryCalculateRuleQuery getSalaryCalculateRuleQuery() {
        SalaryCalculateRuleQuery salaryCalculateRuleQuery = new SalaryCalculateRuleQuery();
        List<SalaryCalculateRuleDO> salaryCalculateRuleDOList = salaryCalculateRuleService.list(new SalaryCalculateRuleDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryCalculateRuleDOList)) {
            SalaryCalculateRuleDO salaryCalculateRuleDO = salaryCalculateRuleDOList.get(0);
            salaryCalculateRuleQuery = salaryCalculateRuleDO.to(SalaryCalculateRuleQuery.class);
        }
        return salaryCalculateRuleQuery;
    }

    /**
     * 保存示例
     * @return SalaryCalculateRuleVO
     */
    public SalaryCalculateRuleVO saveSalaryCalculateRuleExample(){
        SalaryCalculateRuleAddDTO addDTO = this.getSalaryCalculateRuleAddDTO();
        SalaryCalculateRuleVO salaryCalculateRuleVO = salaryCalculateRuleService.save(addDTO,buildTokenUser());
        return salaryCalculateRuleVO;
    }


}

